package com.soft.dao;

import com.soft.entity.OrderInfo;
import com.soft.util.Connect;

import java.util.ArrayList;
import java.util.List;

/**
 * @author kongz
 * @version 1.0 2021/6/7 17:06
 * @description 订单详细信息接口
 */
public class OrderInfoDao {

    private Class<OrderInfo> orderInfoClass;

    public OrderInfoDao() {
        orderInfoClass = OrderInfo.class;
    }

    /**
     * @author kongz 2021/6/7 17:11
     * @description 新建订单的详细信息
     * @param orderInfo 订单详细信息实体类
     * @return boolean
     */
    public boolean insert(OrderInfo orderInfo) {
        List<Object> param = new ArrayList<>();
        param.add(orderInfo.getOrderId());
        param.add(orderInfo.getGoodsId());
        param.add(orderInfo.getCount());

        String sql = "insert into orderinfo(orderid, goodsid, count) VALUE (?,?,?)";

        if (Connect.getInstance().execute(sql, param) != 0)
            return true;
        return false;
    }

    public List<OrderInfo> getByOrderId(int orderId) {
        List<Object> param = new ArrayList<>();
        param.add(orderId);

        String sql = "select * from orderinfo where orderid=?";
        return Connect.getInstance().queryListObject(sql, param, orderInfoClass);
    }
}
